planplus.onFirefoxLoad = function(event) {
	document.getElementById("contentAreaContextMenu")
          .addEventListener("popupshowing", function (e){ planplus.showFirefoxContextMenu(e); }, false);
};

planplus.showFirefoxContextMenu = function(event) {
	if (planplus.initialized == false) planplus.onLoad();
	// show or hide the menuitem based on what the context menu is on
	document.getElementById("context-planplus").hidden = gContextMenu.onImage;
	// Get active window handle
	var focusedWindow = document.commandDispatcher.focusedWindow;
	// Get selected text
	//var txt = unescape(focusedWindow.getSelection().toString());
	var txt = unescape(planplus.getSelection(document.popupNode));
	planplus.txt = txt;
	if (txt == "") {
		document.getElementById("context-planplus").hidden = true;
		return;
	}
	if (txt.length > 18){
		txt = txt.substr(0, 18) + "...";
	}	
	document.getElementById("context-planplus").label = planplus.strings.getString("planplusLabel") + " " + txt;
};

window.addEventListener("load", planplus.onFirefoxLoad, false);
